<title>Search Property</title>
<script>
    $(function() {

        // if direct search from map...
        var stateId = <?= $this->stateId ?>;
        if (stateId != 0) {
            makeRegionHighLited(stateId);
        }

        /**
         * 
         */
        $("ul li").each(function() {
            if ($(this).attr("key") == "search") {
                $(this).addClass("active");
            }
        });


        /**
         * 
         */
        $("select#state").multiselect({
            noneSelectedText: "<?= $this->translate('select_area_location'); ?>",
            selectedText: "# of # <?= $this->translate('select_area_location'); ?>"
        });

        $("select#zipcode").multiselect({
            noneSelectedText: "<?= $this->translate('select_zip'); ?>",
            selectedText: "# of # <?= $this->translate('select_zip'); ?>"
        });

        $("select#propertyType").multiselect({
            noneSelectedText: "<?= $this->translate('select_property_type'); ?>",
            selectedText: "# of # <?= $this->translate('selected_property_type'); ?>"
        });

        $("select#rentalPeriod").multiselect({
            noneSelectedText: "<?= $this->translate('select_rental_period'); ?>",
            selectedText: "# of # <?= $this->translate('selected_rental_period'); ?>"
        });

        $("select#furnishType").multiselect({
            noneSelectedText: "<?= $this->translate('select_furnish_type'); ?>",
            selectedText: "# of # <?= $this->translate('selected_furnish_type'); ?>"
        });

        $("select#rooms").multiselect({
            noneSelectedText: "<?= $this->translate('select_rooms'); ?>",
            selectedText: "# of # <?= $this->translate('selected_rooms'); ?>"
        });

        $("div.ui-multiselect-menu ul.ui-multiselect-checkboxes li").each(function() {
            $(this).addClass("checkbox");
        });
        $("button[type='button'].ui-multiselect").css({
        });


        // Block non-numeric chars.
        $(document).on('keypress', 'input[type=text]', function(event) {
            return (((event.which > 47) && (event.which < 58)) || (event.which == 13));
        });

        $("input[name='submit']").click(function() {
            var doReturn = true;
            var size1 = $("input[name='size1']").val();
            var size2 = $("input[name='size2']").val();
            var rent1 = $("input[name='rent1']").val();
            var rent2 = $("input[name='rent2']").val();
            if (size1 > size2) {
                alert("Value of Max size must be geater or equal to min size.");
                doReturn = false;
            }
            if (rent1 > rent2) {
                alert("Value of Max rent must be greater or equal to min rent.");
                doReturn = false;
            }

            return  doReturn;
        });


    });

    /**
     * 
     * @param {type} stateId
     * @returns {undefined}
     */
    function makeRegionHighLited(stateId) {
        switch (stateId) {
            case 0:
                break;
            case 1:
                temphighlightRegion('storstroem');
                break;
            case 2:
                temphighlightRegion('nordjylland');
                break;
            case 3:
                temphighlightRegion('viborg');
                break;
            case 4:
                temphighlightRegion('aarhus');
                break;
            case 5:
                temphighlightRegion('bornholm');
                break;
            case 6:
                temphighlightRegion('ringkoebing');
                break;
            case 7:
                temphighlightRegion('vejle');
                break;
            case 8:
                temphighlightRegion('ribe');
                break;
            case 9:
                temphighlightRegion('soenderjylland');
                break;
            case 10:
                temphighlightRegion('fyn');
                break;
            case 11:
                temphighlightRegion('vestsjaelland');
                break;
            case 12:
                temphighlightRegion('frederiksborg');
                break;
            case 13:
                temphighlightRegion('roskilde');
                break;
            case 14:
                temphighlightRegion('koebenhavn');
                break;
        }
    }

</script>
<style>
    select{
        /*font-size: 13px;*/
        border: 1px solid #d3d3d3;
        background: #e6e6e6 url(http://code.jquery.com/ui/1.10.3/themes/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png) 50% 50% repeat-x;
        font-weight: normal;
        color: #555555;
    }
    .ui-multiselect, select[name='rooms']{
        width: 100%;
        min-width: 201px;
        height: 30px;
        margin: 1px;
    }


</style>
<?php
$base = "http://" . $_SERVER['SERVER_NAME'];
?>
<div id="view-content">
    <div class="well">
        <div class="row-fluid">
            <div class="span6"  style="height: 400px; margin-top: 30px;">
                <div id="container" class="front-page">
                    <div class="areaSelect">
                        <script src="<?= $base ?>/bootstrap/js/indexf14d.js" type="text/javascript"></script>
                        <div class="areacontent">
                            <div class="map"></div>
                            <div id="mapOverlay" class="map overlay">
                                <map id="regionMap" name="regionMap">
                                    <area shape="rect" alt="Bornholm" title="Bornholm" coords="258,32,320,96" href="/mapsearch/5/map" onmouseover="highlightRegion('bornholm');" />
                                    <area shape="poly" alt="Frederiksborg" title="Frederiksborg" coords="278,231,311,209,337,220,333,246,309,264,296,258,292,239,288,237,280,238" href="/mapsearch/12/map" onmouseover="highlightRegion('frederiksborg');" />
                                    <area shape="poly" alt="Fyn" title="Fyn" coords="172,271,203,274,216,320,223,351,200,391,179,389,131,303,131,291,128,287,157,271" href="/mapsearch/10/map" onmouseover="highlightRegion('fyn');" />
                                    <area shape="poly" alt="K&#248;benhavn" title="K&#248;benhavn" coords="309,263,333,245,351,275,328,291,307,274" href="/mapsearch/14/map" onmouseover="highlightRegion('koebenhavn');" />
                                    <area shape="poly" alt="Nordjylland" title="Nordjylland" coords="249,7,236,114,177,136,138,163,121,145,107,142,96,150,97,143,94,128,89,112,89,27" href="/mapsearch/2/map" onmouseover="highlightRegion('nordjylland');" />
                                    <area shape="poly" alt="Ribe" title="Ribe" coords="26,255,18,279,44,315,76,316,75,302,84,296,93,299,101,287,81,245" href="/mapsearch/8/map" onmouseover="highlightRegion('ribe');" />
                                    <area shape="poly" alt="Ringk&#248;bing" title="Ringk&#248;bing" coords="34,135,57,154,79,156,105,199,113,198,111,225,103,221,93,242,27,254,14,250,18,140" href="/mapsearch/6/map" onmouseover="highlightRegion('ringkoebing');" />
                                    <area shape="poly" alt="Roskilde" title="Roskilde" coords="296,259,309,263,309,274,315,281,314,303,310,308,290,307,287,297,276,283,277,268,285,269,291,265,295,263" href="/mapsearch/13/map" onmouseover="highlightRegion('roskilde');" />
                                    <area shape="poly" alt="Storstr&#248;m" title="Storstr&#248;m" coords="262,331,270,304,276,309,284,315,293,307,311,307,315,300,327,305,333,364,286,410,248,405,211,376,222,354" href="/mapsearch/1/map" onmouseover="highlightRegion('storstroem');" />
                                    <area shape="poly" alt="S&#248;nderjylland" title="S&#248;nderjylland" coords="44,316,39,359,115,378,161,368,130,302,120,308,84,296,75,302,76,316" href="/mapsearch/9/map" onmouseover="highlightRegion('soenderjylland');" />
                                    <area shape="poly" alt="Vejle" title="Vejle" coords="122,232,129,224,152,230,155,246,155,248,160,248,159,266,138,281,128,287,132,291,130,301,118,308,93,299,101,287,81,245,92,242,104,221" href="/mapsearch/7/map" onmouseover="highlightRegion('vejle');" />
                                    <area shape="poly" alt="Vestsj&#230;lland" title="Vestsj&#230;lland" coords="214,222,280,231,279,263,279,264,276,284,286,295,293,307,284,315,274,307,269,307,263,330,228,337,210,261" href="/mapsearch/11/map" onmouseover="highlightRegion('vestsjaelland');" />
                                    <area shape="poly" alt="Viborg" title="Viborg" coords="89,70,89,118,102,137,95,149,107,148,107,142,123,147,138,163,141,189,106,200,74,151,67,160,32,131,33,98" href="/mapsearch/3/map" onmouseover="highlightRegion('viborg');" />
                                    <area shape="poly" alt="Aarhus" title="Aarhus" coords="138,162,188,128,282,129,196,267,159,253,151,229,122,225,110,226,114,197,141,189" href="/mapsearch/4/map" onmouseover="highlightRegion('aarhus');" />
                                </map>
                                <img src="<?= $base ?>/bootstrap/img/transparent.png" alt="" usemap="#regionMap" onmouseout="clearMap();" />
                            </div>
                        </div>	
                    </div>
                </div>
            </div>
            <div style="min-height: 400px;">
                <form method="post" action="/search"  class="span6 well">                    
                    <div class="span12">
                        <h3 style="line-height: 0px;"><?= $this->translate('search'); ?></h3>
                        <hr>
                    </div>
                    <div>
                        <div class="span12">                     
                            <div class="span6"><?= $this->form->state; ?></div>
                            <div class="span6"><?= $this->form->zipcode; ?></div>                                                        
                        </div>
                    </div>
                    <div>
                        <div class="span12">                            
                            <div class="span6"><?= $this->form->propertyType; ?></div>
                            <div class="span6"><?= $this->form->rentalPeriod; ?></div>
                        </div>
                    </div>
                    <div>
                        <div class="span12" style="margin-bottom: 2px;">
                            <div class="span6"><?= $this->form->furnishType; ?></div>
                            <div class="span6"><?= $this->form->rooms; ?></div>                            
                        </div>
                    </div>

                    <div>
                        <div class="span6">
                            <div class="input-prepend" style="float: left; width: 47%;"><span class="add-on"><font size="1em;">Min Size</font></span><?= $this->form->size1; ?></div>
                            <div style="float: left; margin: 0 1% 0 1%; width: 4%;">-</div>
                            <div class="input-prepend" style="float: left; width: 47%;"><span class="add-on"><font size="1em;">Max Size</font></span><?= $this->form->size2; ?></div>
                        </div>
                        <div class="span6">
                            <div class="input-prepend" style="float: left; width: 47%;"><span class="add-on"><font size="1em;">Min Rent</font></span><?= $this->form->rent1; ?></div>
                            <div style="float: left; margin: 0 1% 0 1%; width: 4%;">-</div>
                            <div class="input-prepend" style="float: left; width: 47%;"><span class="add-on"><font size="1em;">Max Rent</font></span><?= $this->form->rent2; ?></div>
                        </div>

                    </div>              
                    <div style="float: right; margin-top: 5%;">
                        <?php if ($this->showResetButton) { ?>
                            <a class="btn btn-info" href="<?= $this->url(array(), 'reset-search'); ?>"> <?= $this->translate('reset'); ?></a>
                        <?php }
                        ?>
                        <?= $this->form->submit ?>
                    </div>                    
                </form>
            </div>
            <div style="float: right;">
                <g:plusone href="http://fedoracores.blogspot.in"></g:plusone>
                <fb:like href="http://www.facebook.com/savantemp" width="260" show_faces="false" send="false"></fb:like>                
            </div>
        </div>        
    </div>
    <h3>
        <?php
        if ($this->stateName != null) {
            echo 'Selected Area Location: ' . $this->stateName . ', ';
        }
        ?>

        <?= $this->translate('total_results_founded') ?>: <?= sizeof($this->searchResult) ?></h3>
    <?php if ($this->searchResult != null): ?>    

        <div class="row-fluid">                    
            <div class="span12">
                <table class="table">
                    <tbody>
                        <?php
                        foreach ($this->searchResult as $detail) :
                            $db = new Ads_Model_Rentdetails();
                            $zipDb = new Ads_Model_Zipcode();
                            $rentDetailsArray = $db->getDetailsJson($detail->details);
                            $photoArray = $db->getPhotoArrayFromJson($rentDetailsArray);
                            ?>                
                            <tr style="height: 100px;">
                                <td class="well" >
                                    <div class="span3"><img src="/uploads/<?= $photoArray[0]; ?>" width="150" height="150" /></div>
                                    <div class="span6" style="margin-left: 10px;">
                                        <div>
                                            <h4><?php echo $rentDetailsArray->adTitle; ?></h4>
                                        </div>
                                        <div>
                                            <?php
                                            $string = $rentDetailsArray->adDesc;
                                            if (strlen($string) > 200) {
                                                $string = substr($string, 0, 200);
                                                $string = $string . '...';
                                            }
                                            echo $string;
                                            ?>
                                        </div>
                                        <div>                                            
                                            <div class="span6">
                                                <i class="search-def search-rent" title="rent/month"></i> <?= $rentDetailsArray->rent; ?> DKK/month<br>
                                                <i class="search-def search-period" title="Rental Period"></i> <?= $db->getRentalPeriod($rentDetailsArray); ?><br>
                                                <i class="search-def search-apartment" title="Property Type"></i> <?= $db->getPropertyType($rentDetailsArray); ?>
                                            </div>
                                            <div class="span6">
                                                <i class="search-def search-city" title="city"></i> <?php
                                                $zipData = $zipDb->getByPrimaryKey($rentDetailsArray->zipcode);
                                                $cityDb = new Ads_Model_City();
                                                $cityData = $cityDb->getCityById($zipData[0]['city_id']);
                                                $stateDb = new Ads_Model_State();
                                                $stateData = $stateDb->getStateById($cityData[0]['state_id']);
                                                echo $str = $zipData[0]['codes'] . ', ' . $cityData[0]['name'] . ', ' . $stateData[0]['name'];
                                                ?><br>
                                                <i class="search-def search-area" title="Area of property"></i> <?= $rentDetailsArray->area; ?> m<sup>2</sup><br>                                                
                                                <i class="search-def search-bedrooms" title="Total Rooms"></i> <?= $rentDetailsArray->rooms; ?> room(s)
                                            </div>
                                        </div>                                    
                                    </div>
                                    <div class="span2">
                                        <a class="btn btn-success" href="<?= $this->url(array('id' => $detail['id']), 'property-details'); ?>"><?= $this->translate('view_details') ?></a>
                                    </div>
                                </td>                            
                            </tr>                              
                            <tr>
                                <td>&nbsp;</td>
                            </tr>
                            <?php
                        endforeach;
                        ?>
                    </tbody>
                </table>                
            </div>
        </div>
    <?php endif; ?>   
</div>
